package jcFrame;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Area;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JPanel;


@SuppressWarnings("serial")
public class close extends JPanel implements MouseListener{
	int x;
	int y;
	Paint _border = new Color(0,0,0,50);
	Paint _bg = new GradientPaint(0, 0, new Color(100,100,100), 0, 30, new Color(150,150,150));
	Paint _hover = new GradientPaint(0, 0, new Color(152,0,0), 0, 30, new Color(212,0,0));
	boolean pressed=false;
	jcFrame _inFrame=null;
	
	close(jcFrame parent){
		_inFrame=parent;
		setOpaque(false);
		setPreferredSize(new Dimension(10,20));
		addMouseListener(this);
	}
	public void paintChildren(Graphics g){
		Graphics2D g2= (Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

		Area bg = new Area(new RoundRectangle2D.Float(-10, 0,getWidth()+10,getHeight(),20,20));
		Area border = new Area(new RoundRectangle2D.Float(-10, 0,getWidth()+10,getHeight(),20,20));
		border.subtract(new Area(new RoundRectangle2D.Float(-10, 1,getWidth()+9,getHeight()-2,18,18)));
		
		
		g2.setPaint(pressed?_hover:_bg);
		g2.fill(bg);
		g2.setPaint(_border);
		g2.fill(border);
		
		
	}
	public void mouseClicked(MouseEvent arg0) {}
	public void mouseEntered(MouseEvent arg0) {}
	public void mouseExited(MouseEvent arg0) {}
	public void mousePressed(MouseEvent e) {
		pressed=true;
		x=e.getX();
		y=e.getY();
		repaint();
	}
	public void mouseReleased(MouseEvent e) {
		pressed=false;
		repaint();
		if(e.getX()==x && e.getY()==y)System.exit(0);
		
	}
}

